<?php
	
	$dbhandle= new PDO('sqlite:./datos/galeria.sqlite');
	$result=NULL;
	$q= NULL;
	if (isset($_GET["nombre"]))
	{
		$GLOBALS['q']=$_GET["nombre"];
		if (strlen($GLOBALS['q']) > 0)			
			$GLOBALS['result']=$dbhandle->query("SELECT NombreP FROM Pinturas");
	}
	if (isset($_GET["artista"]))
	{
		$GLOBALS['q']=$_GET["artista"];
		if (strlen($GLOBALS['q']) > 0)			
			$GLOBALS['result']=$dbhandle->query("SELECT Artista FROM Pinturas");
	}
	if (isset($_GET["etiqueta"]))
	{
		$GLOBALS['q']=$_GET["etiqueta"];
		if (strlen($GLOBALS['q']) > 0)			
			$GLOBALS['result']=$dbhandle->query("SELECT DISTINCT NombreE FROM Etiquetas");
	}
  		
		
  		$hint="";
  		foreach($result as $row)
    	{
    		if (strtolower($GLOBALS['q'])==strtolower(substr($row[0],0,strlen($GLOBALS['q']))))
      		{
      			if ($hint=="")
        		{
        			$hint=$row[0];
        		}
      			else
        		{
        			$hint=$hint." , ".$row[0];
        		}
      		}
    	}
		
	if ($hint == "")
  	{
  		$response="no suggestion";
  	}
	else
  	{
  		$response=$hint;
  	}
	
	$dbhandle= NULL;

	echo $response;
?>